package String;

public class item28 {
    public static int strStr(String haystack, String needle) {
        if(needle.length()==0) return 0;
        if(haystack.length()==0) return -1;
        int start = 0;
        int i = start;
        int j = 0;
        while (i<haystack.length()&&j<needle.length())
        {
            if(haystack.charAt(i)==needle.charAt(j))
            {
                i++;
                j++;
            }
            else
            {
                start++;
                i = start;
                j=0;
            }

        }
        if(j>=needle.length()) return start;
        else  return -1;

    }

    public static void main(String[] args) {
        String haystack = "mississippi";
        String needle= "issip";
        strStr(haystack,needle);
    }
}
